package com.scuec.tourismwebsite.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.scuec.tourismwebsite.entity.BoutiqueTour;
import com.scuec.tourismwebsite.entity.User;
import com.scuec.tourismwebsite.entity.UserOrder;
import com.scuec.tourismwebsite.mapper.UserOrderMapper;
import com.scuec.tourismwebsite.vo.OrderUserBoutique;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Map;

@Service
public class UserOrderServiceImpl implements UserOrderService {
    @Autowired
    private UserOrderMapper userOrderMapper;
    @Autowired
    private BoutiqueTourService boutiqueTourService;

    @Override
    public List<OrderUserBoutique> findOrderByUsername(String nickname) {
        return userOrderMapper.findOrderByUsername(nickname);
    }

    @Override
    public int deleteOrderById(int order_id) {
        return userOrderMapper.deleteOrderById(order_id);
    }

    @Override
    public List<OrderUserBoutique> findOrderAll() {
        return userOrderMapper.findOrderAll();
    }

    @Override
    public List<OrderUserBoutique> findOrderToAll() {
        return userOrderMapper.findOrderToAll();
    }

    @Override
    public PageInfo<OrderUserBoutique> findOrderPages(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<OrderUserBoutique> lists = userOrderMapper.findOrderAll();
        PageInfo<OrderUserBoutique> pageInfo = new PageInfo<>(lists);
        return pageInfo;
    }

    @Override
    public PageInfo<OrderUserBoutique> findOrderPage(String nickname,Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<OrderUserBoutique> lists = userOrderMapper.findOrderByUsername(nickname);
        PageInfo<OrderUserBoutique> pageInfo = new PageInfo<>(lists);
        return pageInfo;
    }
    @Override
    public PageInfo<OrderUserBoutique> findAnaPages(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<OrderUserBoutique> lists = userOrderMapper.findOrderToAll();
        PageInfo<OrderUserBoutique> pageInfo = new PageInfo<>(lists);
        return pageInfo;
    }

    @Override
    public PageInfo<OrderUserBoutique> findAnaPage(String tour_name,Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<OrderUserBoutique> lists = userOrderMapper.findAnaByname(tour_name);
        PageInfo<OrderUserBoutique> pageInfo = new PageInfo<>(lists);
        return pageInfo;
    }

    @Override
    public List<OrderUserBoutique> findOrdersByUserId(Integer user_id) {
        return userOrderMapper.findOrderByUserId(user_id);
    }

    @Override
    public UserOrder findOrderById(Integer order_id) {
        return userOrderMapper.findOrderById(order_id);
    }



    @Override
    public int insertUserOrder(UserOrder userOrder) {
        return userOrderMapper.insertUserOrder(userOrder);
    }

    @Override
    public int getTotalOrders() {
        return userOrderMapper.countOrders();
    }

    @Override
    public float getTotalOrderAmount() {
        return userOrderMapper.sumOrderAmounts();
    }
    @Override
    public List<Map<String, Object>> getTop7Tours() {
        return userOrderMapper.findTop7Tours();
    }
    @Override
    public List<Map<String, Object>> getOrderTrend() {
        return userOrderMapper.findOrderTrend();
    }
    @Override
    public List<Map<String, Object>> getPriceSalesData() {
        return userOrderMapper.findPriceSalesData();
    }
}